%%
clear; clc;
path = pwd;
addpath(genpath(path));
addpath(fullfile(pwd, '..', 'lib'));
 dataName = { 'ALLAML_72n_7129d_2c_12k_amkkc_multi_kernel', 'BASEHOCK_1993n_4862d_2c_tfidf_uni_12k_amkkc_multi_kernel',...
        'bbcnewssport_737n_1000d_5c_uni_12k_amkkc_multi_kernel', 'COIL20_1440n_1024d_20c_uni_12k_amkkc_multi_kernel',...
        'leukemia_72n_7070d_2c_12k_amkkc_multi_kernel','RELATHE_1427n_4322d_2c_tfidf_uni_12k_amkkc_multi_kernel',...
      'UMIST_575n_644d_20c_12k_amkkc_multi_kernel','warpPIE10P_210n_2420d_10c_12k_amkkc_multi_kernel',...
};
mubiao=[];
for i2 = 1:length(dataName)
     load(fullfile(pwd, '..', 'result', dataName{i2}));
     s=0;
     sm=0;
    for i1=(1:11) 
        if sm<sum(res_amkkc_aio(i1,:))
           sm=sum(res_amkkc_aio(i1,:));
           s=i1/10;
        end
    end
    s=s+1;
    mubiao=[mubiao;s];
end
save(['obj.mat'],'mubiao');

%%
clear; clc;
path = pwd;
addpath(genpath(path));
addpath(fullfile(pwd, '..', 'lib'));
 dataName =  { 'ALLAML_72n_7129d_2c_12k', 'BASEHOCK_1993n_4862d_2c_tfidf_uni_12k',...
        'bbcnewssport_737n_1000d_5c_uni_12k', 'COIL20_1440n_1024d_20c_uni_12k',...
        'leukemia_72n_7070d_2c_12k','RELATHE_1427n_4322d_2c_tfidf_uni_12k',...
      'UMIST_575n_644d_20c_12k','warpPIE10P_210n_2420d_10c_12k',...
};
for i1 = 1:length(dataName)
    load(fullfile(pwd, '..', 'data', dataName{i1}));
    load(fullfile(pwd,'obj'));
    lambdas =1.2%mubiao(i1,1); % trade-off
   % trade-off 
    ks = [5];
    Ks2 = zeros(size(Ks));
    for i2 = 1:size(Ks,3)
        Ktmp = knorm(Ks(:,:,i2));
        if max(Ktmp(:)) > 1
            Ktmp = Ktmp  / max(Ktmp(:));
        end
        Ks2(:,:,i2) = Ktmp;
    end
    clear Ks;
    nRepeat = 1;
    [objHistory] = AMKKC_single_dataset(Ks2, Y, lambdas,ks,nRepeat);
    save(['obj\',dataName{i1}, '_amkkc.mat'],'objHistory');  

end

%%
clear; clc;
path = pwd;
addpath(genpath(path));
addpath(fullfile(pwd, '..', 'lib'));
data =  { 'ALLAML_72n_7129d_2c_12k_amkkc', 'BASEHOCK_1993n_4862d_2c_tfidf_uni_12k_amkkc',...
        'bbcnewssport_737n_1000d_5c_uni_12k_amkkc', 'COIL20_1440n_1024d_20c_uni_12k_amkkc',...
        'leukemia_72n_7070d_2c_12k_amkkc','RELATHE_1427n_4322d_2c_tfidf_uni_12k_amkkc',...
      'UMIST_575n_644d_20c_12k_amkkc','warpPIE10P_210n_2420d_10c_12k_amkkc',...
};
 dat={'ALLAML','BASEHOCK','BBC','COIL20','Leukemia','RELATHE','UMIST','PIE10P'};   
for i1 =1:length(data)
    load(fullfile(pwd,'obj',data{i1}));
    y=objHistory;
    s=length(y);
    plot(y,'-b','LineWidth',1); 
    set(gca,'linewidth',1,'fontsize',12,'fontname','Times','FontWeight','bold');
    xlabel('Number of iteration','FontWeight','bold');
    ylabel('Objective Values','FontWeight','bold');
    title(strrep(dat{i1},'_','\_'));
    set(gca,'xlim',[1,s],'xtick',[1,[2:s]]);
    save2pdf(['converge\','converge_',dat{i1},'.pdf']);
end    

